﻿using System;

namespace paiban.data
{
    using xlstool;
    internal class DasaoTableThumb
    {
        internal int[] thumb_sum;
        internal string[] personmap;
        internal int thumb_sum_count;
        internal DasaoTable table { get; set; }
        public DasaoTableThumb(DasaoTable table)
        {
            this.table = table;
            thumb_sum_count = table.info.work_person_count;
            thumb_sum = new int[thumb_sum_count];
            personmap = new string[thumb_sum_count];
        }
        public void Update()
        {
            var ix = 0;
            foreach (var person in table.info.LoopWorkPersons())
            {
                personmap[ix] = person;
                thumb_sum[ix] = table.daosao_table.Count(t => t == person);
                ix++;
            }
        }
        public int ReadPersonCount(string person)
        {
            return thumb_sum[Array.IndexOf(personmap, person)];
        }
        public void FillExcelSheet(Excel2003Sheet pb)
        {

            var rowno = 1;
            foreach (var person in table.info.LoopWorkPersons())
            {
                var row = pb.ToRow(rowno++);
                row.ToCell(1).SetValue(person);
                row.ToCell(2).SetValue(ReadPersonCount(person));
            }
        }
    }
}
